%
%  pyPhon
%
%----------------------------------------------------------------------------%
%                    Basic page layout parameters                            %
%----------------------------------------------------------------------------%

\documentclass[11pt,openany,leqno,tbtags]{book}
    % leqno = equations at the left
    % tbtags (+leqno) = equation numbers at the top (rather than centered) 

\usepackage[letterpaper,hmargin=1.125in,vmargin=1.125in]{geometry} 

\usepackage[bottom]{footmisc}

\usepackage{fancyhdr}
\lhead{Bane and Riggle}
\chead{}
\rhead{pyPhon 1.0 (\today)}
\lfoot{}
\cfoot{}
\rfoot{\vspace{1ex} \thepage}
\pagestyle{fancy}

\usepackage{setspace}
\spacing{1.25}

\usepackage{enumitem}
\setlist{noitemsep} 

%----------------------------------------------------------------------------%
%                    Title, author, and affiliation                          %
%----------------------------------------------------------------------------%

\title{%
\psset{yunit=9mm}
\begin{pspicture}(10,4)%\psgrid
\rput(5,4.5){\scalebox{3}{\textbf{pyPhon 1.0}}}
\psline[linewidth=5pt](0,6)(10,6)    
\psline[linewidth=5pt](0,3)(10,3)
\rput(5,2.2){\scalebox{0.85}{\textbf{A toolkit for constraint-based grammars}}}
\rput(5,0.5){\Large Max Bane \& Jason Riggle}    
\rput(5,-.25){\Large University of Chicago}
\rput(5,-1.0){\Large \today}
\end{pspicture}
\large
\scalebox{0.8}{%
\psset{framearc=0.1,xunit=12.25mm,yunit=6.5mm,dash=3pt 2pt}
\begin{pspicture}(0,1)(11,18)%\psgrid
    \psframe[linecolor=gray7,fillstyle=solid,%
    fillcolor=gray9,framearc=0.05](-0.5,0)(11.5,11)
	\psline[arrowsize=0.25,linewidth=2pt]{->}(4.1,8)(4.8,8)
	\psline[arrowsize=0.25,linewidth=2pt]{->}(6,6.7)(6,5.3)
    \psline[arrowsize=0.25,linewidth=2pt]{->}(8.1,3)(8.8,3)
	\psframe[linewidth=1.5pt,fillstyle=solid,fillcolor=white](0,6)(4,10)
	\psframe[fillstyle=solid,framearc=0.2,linewidth=0.5pt,linestyle=dashed,
	fillcolor=ltblue](0,9)(4,10)	
	\psframe[linewidth=1.5pt](0,6)(4,10)
	\rput[l](0.2,9.5){\texttt{\textbf{pyphon\_maketableaux}}}
	\rput[rB](1.1,8.35){\emph{input:}} 
	\rput[lB](1.2,8.35){\textbf{model.csv}}
	\rput[l](1.2,7.6){\textbf{inputs.csv}}
	\rput[rB](1.1,6.35){\emph{option:}}
	\rput[lB](1.2,6.35){OT/HG}
    \pscustom[linewidth=1.5pt,fillstyle=solid,fillcolor=ltred]{ 
        \psbezier(4.9,7.2)(6,6.5)(6,7.9)(7.1,7.2)
        \psline[linearc=.2](7.1,8.9)(4.9,8.9)(4.9,8.2)
        \closepath}
	\rput(6,8.1){\textbf{tableaux.csv}}
	\psframe[linewidth=1.5pt,fillstyle=solid,fillcolor=white](4,1)(8,5)
	\psframe[fillstyle=solid,framearc=0.2,linewidth=0.5pt,linestyle=dashed,
	fillcolor=ltblue](4,4)(8,5)	
	\psframe[linewidth=1.5pt](4,1)(8,5)
	\rput[l](4.2,4.5){\texttt{\textbf{pyphon\_generate}}}
	\rput[rB](5.1,3.35){\emph{input:}} 
	\rput[lB](5.2,3.35){\textbf{tableaux.csv}}
	\rput[l](5.2,2.6){\textbf{grammars.csv}}
	\rput[rB](5.1,1.35){\emph{option:}}
	\rput[lB](5.2,1.35){which grammar}
    \pscustom[linewidth=1.5pt,fillstyle=solid,fillcolor=ltred]{ 
        \psbezier(8.9,2.2)(10,1.4)(10,3.0)(11.1,2.2)
        \psline[linearc=.2](11.1,3.9)(8.9,3.9)(8.9,2.2) 
        \closepath}
	\rput(10,3){\textbf{typology.csv}}
\end{pspicture}}
}
\author{}
\date{}

%----------------------------------------------------------------------------%
%                    Fonts and encoding                                      %
%----------------------------------------------------------------------------%

\usepackage[dirty,tipa]{ucs}	% Utf-8
\usepackage[utf8x]{inputenc}	% fonts
\usepackage[T1]{fontenc}		% in Tex

\usepackage{tipa}
\usepackage{pifont}
\usepackage{palatino}           % body font 
\renewcommand{\ttdefault}{lmtt} % tt set to latinmodern




%----------------------------------------------------------------------------%
%                    Graphics and figures                                    %
%----------------------------------------------------------------------------%

\usepackage{wrapfig}
\usepackage{graphicx}
\usepackage{multido}
\usepackage{pstricks}

\psset{gridcolor=green, subgridcolor=white, dimen=middle,
	   linewidth=1pt, subgriddiv=1, gridlabels=4pt, gridwidth=0.2pt}
\psset{cornersize=absolute,linearc=0.06}
		
\newpsstyle{final}{linewidth=0.5pt,fillstyle=solid,fillcolor=gray95,%
				   doubleline=true,doublesep=0.8pt,dimen=outer}


%----------------------------------------------------------------------------%
%                    Algorithms and Theorems                                 %
%----------------------------------------------------------------------------%

\usepackage[ruled,noend,linesnumbered]{algorithm2e}

\usepackage[leqno,fleqn]{amsmath}
\usepackage{amsthm}
\usepackage{amssymb} 
\usepackage{stmaryrd}

\newtheoremstyle%
{dotless}%      name
{\topsep}%      Space above
{\topsep}%      Space below
{\normalfont}%  Body font
{}%             Indent amount (empty = no indent, \parindent = para indent)
{\bfseries}%    Thm head font
{}%             Punctuation after thm head
{\newline}%     Space after head: " " = interword space, \newline = linebreak
{}%             Thm head spec (can be left empty, meaning `normal')
%               alternative spec: {\thmname{#1}\thmnumber{ #2}\thmnote{ (#3)}}

\theoremstyle{dotless}

\newtheorem{thm}{Theorem}[section]
\newtheorem{cor}[thm]{Corollary}
\newtheorem{lem}[thm]{Lemma}
\newtheorem{exe}[thm]{Example}


%----------------------------------------------------------------------------%
%                    Bibliography                                            %
%----------------------------------------------------------------------------%

\usepackage{natbib} 
\bibpunct[:]{(}{)}{,}{a}{}{,}

%----------------------------------------------------------------------------%
%                    Hyperlinks                                              %
%----------------------------------------------------------------------------%

\usepackage{hyperref}			% Clickable links in pdfs
\hypersetup{colorlinks,			% nice for large docs and 
			breaklinks,			% for links to web pages
            linkcolor=black,
			urlcolor=darkblue,
            anchorcolor=darkblue,
			citecolor=black}

			%----------------------------------------------------------------------------%
%                    Other packages                                          %
%----------------------------------------------------------------------------%

\usepackage{calc}
\usepackage{ifthen}
			
%----------------------------------------------------------------------------%
%                    New Commands                                            %
%----------------------------------------------------------------------------%

\newcommand{\hand}{{\large \ding{43}}}		% OT-Hand
\newcommand{\Con}[1]{{\sc #1}}				% Constraint-name typeface
\newcommand{\M}[1]{$\llbracket${\sc #1}%	% 'FSA-name' typeface
				   $\rrbracket$}

\newcommand{\Adm}[1]{\text{\raisebox{2pt}{$\,\underrightarrow{#1}\,$}}}

%\newcommand{\Or}{\begin{pspicture}(0.25,0)
%		\rput(0.1,0.1){\scalebox{0.58}{$\mathcal{R}$}}
%		\pscircle[linewidth=0.2pt](0.1,0.1){0.125}\end{pspicture}}

\newcommand{\Or}{\ensuremath{\min_\mathcal{R}}}
\newcommand{\Ur}{\ensuremath{\sqcup_\mathcal{R}}}
\newcommand{\Ptr}{\ensuremath{\times_\mathcal{R}}}

\newcommand{\stack}[2]{\genfrac{}{}{0pt}{}{#1}{#2}}
\newcommand{\NIL}{\ensuremath \varnothing}
\newcommand{\NILc}{$\NIL,\{\epsilon\}$}
\newcommand{\INF}{{\scriptsize $\infty$}}
\newcommand{\INFc}{{\scriptsize $\infty$}\hspace{0.5pt},$\;\emptyset$}
\newcommand{\odv}{\begin{pspicture}(0,0)
\rput(-.05,0.19){{\footnotesize $ons,$}}
\rput(0.05,-.18){{\footnotesize $dpv$}}
\end{pspicture}}
\newcommand{\dvc}{\begin{pspicture}(0,0)
\rput(0,0.2){{$dpv,$}}
\rput(0.1,-.2){{$dpc$}}
\end{pspicture}}
\newcommand{\minn}{{\textbf{min}}}
\newcommand{\hopt}{$\mathcal{H}$\Con{-Opt}}
\newcommand{\minr}[2]{\textbf{min}$_{\mathcal{R}}$(#1,#2)}
\newcommand{\Hr}{$\succ_{\mathcal{R}}$}
\newcommand{\con}{{\sc Con}}
\newcommand{\cinf}{$\infty$}
\newcommand{\rd}[1]{\textcolor{red}{\textbf{#1}}}
\newcommand{\bl}[1]{\textcolor{blue}{\textbf{#1}}}
\newcommand{\pur}[1]{\textcolor{purp}{\textbf{#1}}}
\newcommand{\eval}{E{\footnotesize{VAL}}}
\newcommand{\heval}{$\mathcal{H}$-E{\footnotesize{VAL}}}
%\newcommand{\evala}{$\llbracket$E{\footnotesize{VAL}}$_\mathcal{A}\rrbracket$}
\newcommand{\evala}{$\llbracket$E{\footnotesize{VAL}}$\rrbracket$}
\newcommand{\gen}{\ensuremath{Gen}}
\newcommand{\io}{$(input,output)$ }
\newcommand{\D}{{\Large\bf{.}}}
\newcommand{\DOT}{{\Large\bf{.}}}
\newcommand{\depc}{{\sc{DepC}}}
\newcommand{\depv}{{\sc{DepV}}}
\newcommand{\Max}{{\sc{Max}}}
\newcommand{\ons}{{\sc{Onset}}}
\newcommand{\noc}{{\sc{NoCoda}}}
\newcommand{\cln}{\hspace{1pt}:\hspace{1pt}}
\newcommand{\aaa}{$\alpha$$\to$$\alpha$\cln\oset}
\newcommand{\maxa}{\Con{x}$\to$$\varnothing$\cln\{$max$\}}
\newcommand{\depa}{$\varnothing$$\to$\Con{x}\cln\{$dep$\}}
\newcommand{\dep}[1]{$\varnothing$$\to$\Con{#1}\cln%
										 \{$dep$\hspace{0.33pt}-\Con{#1}\}}

%----------------------------------------------------------------------------%
%                    New colors                                              %
%----------------------------------------------------------------------------%

\newrgbcolor{purp}{0.7 0.0 0.7}
\newrgbcolor{ltblue}{0.8 0.9 1.0}
\newrgbcolor{ltgreen}{0.8 1.0 0.85}
\newrgbcolor{ltred}{1.0 0.9 0.8}
\newrgbcolor{red}{0.7 0.0 0.0}
\newrgbcolor{blue}{0.0 0.0 0.7}
\newrgbcolor{darkblue}{0.0 0.0 0.4}
\newrgbcolor{ltelo}{1.0 1.0 0.8}
\newrgbcolor{ltpurple}{1 0.8 1}

\newgray{gray4}{0.4}
\newgray{gray6}{0.6}
\newgray{gray7}{0.7}
\newgray{gray8}{0.8}
\newgray{codeBackground}{0.7}
\newgray{gray9}{0.9}
\newgray{gray90}{0.9}
\newgray{gray95}{0.95}
\newgray{gray97}{0.97}

\usepackage{pstcol}
\usepackage{pst-grad}

\definecolor{Orange}      {rgb}{1.,0.65,0.}

%----------------------------------------------------------------------------%
%  Code Display Environment
%----------------------------------------------------------------------------%
% Usage:  \begin{CodeFrom}{<filename>}{<reflabel>}
%         [displayed verbatim]
%         \end{CodeFrom}
%
%   To omit the file-tab below the code block, use {} for {<filename>}.

\usepackage{fancyvrb,color}
\usepackage{xspace}

% Use this to refer to examples: 

\newcommand{\refex}[1]{example (\ref{#1})\xspace} 

        %------------------------------------------------------------%

\makeatletter       % Make the special character `@' accessible 

\newcounter{codeverb}
\numberwithin{codeverb}{section}

\define@key{FV}{reflabel}{%
   \def\@tempa{#1}\ifx\@tempa\empty\relax\else\label{#1}\fi}

\def\NumSaveVerbatim{\FV@Environment{}{NumSaveVerbatim}} 

\def\FVB@NumSaveVerbatim#1{%
\refstepcounter{codeverb}%
\filbreak\par\vspace{16pt}%
\noindent\raisebox{4pt}{\textbf{Example~\thecodeverb}}%
\@bsphack 
\begingroup 
\FV@UseKeyValues 
\def\NumSaveVerbatim@Name{#1}% 
\gdef\FV@TheVerbatim{}% 
\def\FV@ProcessLine##1{% 
\expandafter\gdef\expandafter\FV@TheVerbatim\expandafter{% 
\FV@TheVerbatim\FV@ProcessLine{##1}}}% 
\gdef\FV@TheVerbatim{}% 
\FV@Scan} 

\def\FVE@NumSaveVerbatim{% 
\expandafter\global\expandafter\let 
\csname FV@SV@\NumSaveVerbatim@Name\endcsname\FV@TheVerbatim 
\endgroup\@esphack} 

\DefineVerbatimEnvironment{NumSaveVerbatim}{NumSaveVerbatim}{} 

\makeatother        % Occlude the special character `@'

        %------------------------------------------------------------%

\newsavebox{\HoldFileName}
\newlength{\FileNameWidth}

\newenvironment{CodeFrom}[2]%
{\sbox{\HoldFileName}{\small #1}\settowidth{\FileNameWidth}{#1}%
\NumSaveVerbatim[reflabel=#2]{CodeFromEnv}}%
{\endNumSaveVerbatim\noindent%
\psframebox*[fillcolor=codeBackground,linearc=0.06,framesep=8pt]%
{\parbox{0.96\textwidth}{\scalebox{0.95}{\BUseVerbatim{CodeFromEnv}}%
}}~\\\phantom{labelspace}
\ifthenelse{\lengthtest{\FileNameWidth>1em}}{%
\rput[r](0.85\textwidth,0.1){%
\psframebox*[fillcolor=codeBackground,framesep=4pt,linearc=0.1]{%
\raisebox{-12pt}{\small\textbf{from: }%
\texttt{\usebox{\HoldFileName}}}}}%
{}}~\\}


%----------------------------------------------------------------------------%
%                    A tableau environment                                   %
%  [#1-1st Col %-width]  #2-n.Constraints   #3-n.Candidates   #4-Col wid/cm  %
%----------------------------------------------------------------------------%
\newcounter{xc}	  \newcounter{x0}
\newcounter{yc}	  \newcounter{y0}	  
\newcounter{zc}   \newcounter{z0}		\newlength{\rowmax} 
\newlength{\col}  \setlength{\col}{1mm}
\newlength{\row}  \setlength{\row}{1.1mm}
\newboolean{ding} \setboolean{ding}{false}

\newenvironment{tableau}[4][2]{%
\bigskip\medskip\refstepcounter{equation}%
\setcounter{xc}{#2-1}   		\setcounter{x0}{#2}
\setcounter{yc}{#3+1}  			\setcounter{y0}{#3}
\setcounter{zc}{10*\real{#1}-5} \setcounter{z0}{10*\real{#1}-5}
\setcounter{enumi}{1}
\psset{xunit=#4mm,yunit=1.5pt,linewidth=0.6pt,framearc=0}
\noindent\begin{pspicture}(0,0)\rput[l](0,#35){(\theequation)}\end{pspicture}%
\hspace*{8.75mm} %<--Tableau inset
\begin{pspicture}(-\arabic{z0},5)(\arabic{x0}5,\arabic{yc}5)%\psgrid
\multido{\ir=#30+-10}{#3}{\rput[l](-\arabic{z0},\ir)%
		{\hspace{2pt}\textit{\alph{enumi}}.\stepcounter{enumi}}}
\setcounter{xc}{#2+1} \setcounter{yc}{#30+10}
\setlength{\rowmax}{\arabic{xc}mm} \setcounter{xc}{0}
\psdot[linecolor=white](0,30)}{ %Begin Code -|- End Code
\setcounter{yc}{\value{y0}+1}
\multido{\nh=05+10}{\arabic{x0}}{\psline[linestyle=dashed,dash=2pt 1pt,%
		linewidth=0.5pt,dimen=middle](\nh,5)(\nh,\arabic{yc}5)}
\multido{\nw=15+10}{\arabic{y0}}{\psline(-\arabic{z0},\nw)(\arabic{x0}5,\nw)}
\psline[linewidth=1.4pt](5,5)(5,\arabic{yc}5)
\psline[linewidth=1.4pt](-\arabic{z0},\arabic{y0}5)(\arabic{x0}5,\arabic{y0}5)
\psline[linecolor=white](5,5)(5,\arabic{yc}5)
\psline[linecolor=white](-\arabic{z0},\arabic{y0}5)(\arabic{x0}5,\arabic{y0}5)
\psframe[linewidth=1pt,framearc=0.025,dimen=middle]%
(-\arabic{z0},5)(\arabic{x0}5,\arabic{yc}5)
\end{pspicture}\par\medskip}

\newcounter{n1}	\newcounter{n2}
\newcommand{\Shade}[5][gray90]{%
			\setcounter{n1}{#2*10-5}\setcounter{n2}{#3*10-5}
			\psframe*[linecolor=#1](\arabic{n1},\arabic{n2})(#45,#55)}

\newcommand{\Wins}[1]{\setcounter{n1}{\value{y0}-#1+1}%
			\setboolean{ding}{true}%
			\rput[l](-\arabic{z0},\arabic{n1}0){~~~\hand}}
			
\newcommand{\Solid}[1]{\setcounter{n1}{\value{y0}+1}
			\psline[linewidth=0.8pt,dimen=middle](#15,5)(#15,\arabic{n1}5)}

\newcommand{\C}[1]{\ifthenelse{\lengthtest{\row=1.1mm}}{%
		   	\rput[l](-\arabic{z0},\arabic{yc}){%
			\ifthenelse{\lengthtest{\col>\row}}{\hspace{5mm}%
			\ifthenelse{\boolean{ding}}{\phantom{\hand}}{}#1}%
			{\hspace*{3mm}#1}}
		   	\addtocounter{xc}{10}\addtolength{\row}{1mm}}{%
		   	\rput(\arabic{xc},\arabic{yc}){%
			\ifthenelse{\lengthtest{\col>\row}}{#1}{\Con{#1}}}
		   	\ifthenelse{\lengthtest{\row<\rowmax}}%
		   	{\addtocounter{xc}{10}\addtolength{\row}{1mm}}%
		   	{\setcounter{xc}{0}\addtocounter{yc}{-10}
		    \addtolength{\col}{10cm}\setlength{\row}{1.1mm}}}}



%%%%%%%%%-%%%%%%%%%-%%%%%%%%%-%%%%%%%%%-%%%%%%%%%-%%%%%%%%%-%%%%%%%%%-%%%%%%%%
%./\..../\..../\..../\..../\..../\..../\..../\..../\..../\..../\..../\..../\.%
%/  \../  \../  \../  \../  \../  \../  \../  \../  \../  \../  \../  \../  \%
%    \/    \/    \/    \/    \/    \/    \/    \/    \/    \/    \/    \/    %
%%%%%%%% %%%%%%%% %%%%%%%% %%%%%%%% %%%%%%%% %%%%%%%% %%%%%%%% %%%%%%%% %%%%%%


\begin{document}
\maketitle 
\tableofcontents
%%%%%%%%%-%%%%%%%%%-%%%%%%%%%-%%%%%%%%%-%%%%%%%%%-%%%%%%%%%-%%%%%%%%%-%%%%%%%%
%./\..../\..../\..../\..../\..../\..../\..../\..../\..../\..../\..../\..../\.%
%/  \../  \../  \../  \../  \../  \../  \../  \../  \../  \../  \../  \../  \%
%    \/    \/    \/    \/    \/    \/    \/    \/    \/    \/    \/    \/    %
%%%%%%%% %%%%%%%% %%%%%%%% %%%%%%%% %%%%%%%% %%%%%%%% %%%%%%%% %%%%%%%% %%%%%%

\chapter{Introduction}

pyPhon is a suite of software written in Python designed to aid in phonological analysis with consraint-based models. It is designed to serve two main functions: first, pyPhon can take a set of constraints expressed via regular expressions and generate, for a given set of input forms, a set of tableaux that are \emph{complete} in the sense that they contain \emph{all} potentially optimal candidates. Second, pyPhon can take these tableaux (or any set of hand-crafted tableaux supplied by the user),\footnote{Using hand-crafted tableaux, the system is comparable to OTsoft or OThelp.} and generate linguistic typologies. Furthermore, it can either (i) produce the grammars that are consistent with a set of specified optima or (ii) produce optima that are consistent with a specified grammar (or set of grammars). All of these functions can be specified to use either ranked constraints or weighted constraints. A basic overview is given in Fig.\ \ref{fig:overview}.

\begin{figure}[ht] \centering
\psset{framearc=0.1,xunit=12.25mm,yunit=6.5mm,dash=3pt 2pt}
\begin{pspicture}(0,1)(11,13.5)\psgrid

	\psline[arrowsize=0.25,linewidth=2pt]{->}(1,11.4)(1,10.2)
	\psline[arrowsize=0.25,linewidth=2pt]{->}(3,11.4)(3,10.2)
	\psline[arrowsize=0.25,linewidth=2pt]{->}(4.1,8)(4.8,8)
	\psline[arrowsize=0.25,linewidth=2pt]{->}(6,6.7)(6,5.3)
	\psline[arrowsize=0.25,linewidth=2pt]{->}(8.1,3)(8.8,3)
	\psline[arrowsize=0.25,linewidth=2pt]{->}(3.2,3)(3.9,3)

    \pscustom[linewidth=1.5pt,fillstyle=solid,fillcolor=ltgreen]{ 
        \psbezier(0.1,11.7)(1,11.1)(1,12.1)(1.9,11.7)
        \psline[linearc=.2](1.9,13)(0.1,13)(0.1,12) 
        \closepath}
	\rput(1,12.4){\textbf{model.csv}}

    \pscustom[linewidth=1.5pt,fillstyle=solid,fillcolor=ltgreen]{ 
        \psbezier(2.1,11.7)(3,11.1)(3,12.1)(3.9,11.7)
        \psline[linearc=.2](3.9,13)(2.1,13)(2.1,12) 
        \closepath}
	\rput(3,12.4){\textbf{inputs.csv}}


	\psframe[fillstyle=solid,framearc=0.2,linewidth=0.5pt,linestyle=dashed,
	fillcolor=ltblue](0,9)(4,10)	
	\psframe[linewidth=1.5pt](0,6)(4,10)
	\rput[l](0.2,9.5){\texttt{\textbf{pyphon\_maketableaux}}}
	\rput[rB](1.1,8.35){\emph{input:}} 
	\rput[lB](1.2,8.35){\textbf{model.csv}}
	\rput[l](1.2,7.7){\textbf{inputs.csv}}
	\rput[rB](1.1,6.35){\emph{option:}}
	\rput[lB](1.2,6.35){OT/HG}

    
    \pscustom[linewidth=1.5pt,fillstyle=solid,fillcolor=ltred]{ 
        \psbezier(4.9,7.2)(6,6.5)(6,7.9)(7.1,7.2)
        \psline[linearc=.2](7.1,8.9)(4.9,8.9)(4.9,8.2)
        \closepath}
	\rput(6,8.1){\textbf{tableaux.csv}}

	\psframe[fillstyle=solid,framearc=0.2,linewidth=0.5pt,linestyle=dashed,
	fillcolor=ltblue](4,4)(8,5)	
	\psframe[linewidth=1.5pt](4,1)(8,5)
	\rput[l](4.2,4.5){\texttt{\textbf{pyphon\_generate}}}
	\rput[rB](5.1,3.35){\emph{input:}} 
	\rput[lB](5.2,3.35){\textbf{tableaux.csv}}
	\rput[l](5.2,2.7){\textbf{grammars.csv}}
	\rput[rB](5.1,1.35){\emph{option:}}
	\rput[lB](5.2,1.35){which grammar}

    \pscustom[linewidth=1.5pt,fillstyle=solid,fillcolor=ltred]{ 
        \psbezier(8.9,2.2)(10,1.4)(10,3.0)(11.1,2.2)
        \psline[linearc=.2](11.1,3.9)(8.9,3.9)(8.9,2.2) 
        \closepath}
	\rput(10,3){\textbf{typology.csv}}
	
    \pscustom[linewidth=1.5pt,fillstyle=solid,fillcolor=ltgreen]{ 
        \psbezier(0.8,2.2)(1.95,1.4)(1.95,3.0)(3.1,2.2)
        \psline[linearc=.2](3.1,3.9)(0.8,3.9)(0.8,2.2) 
        \closepath}
	\rput(1.95,3){\textbf{grammars.csv}}
\end{pspicture}
\caption{pyPhon flow chart} \label{fig:overview}
\end{figure}
\vspace{4pt}

\section{Outline}
These functions and file structures will be illustrated in the next few sections. First, in \S \ref{sec:setup} we give basic instructions for obtaining and installing pyPhon (for more extensive directions and troubleshooting the web pages should be consulted). In \S \ref{sec:cvsyllables} we introduce the constraint description language and model description files. Users wishing to use the algorithms on hand-constructed tableaux can skip to the second half of the section. In \S \ref{sec:stress} we illustrate more kinds of constraints using several models of QI and QS stress. In this section we also go into greater detail about some of the options for typology construction. These sections are meant as a practical guide to getting a model implemented and running. Discussion of the algorithms and their python implementation is saved for part 2. 




%----------------------------------------------------------------------------%
% Setup
%----------------------------------------------------------------------------%

\section{Setting up pyPhon}\label{sec:setup}

\hspace{8cm}

Where to get it. How to do it. Running the scripts, screenshots? Introduce our
conventions for representing terminal input/output.

\begin{CodeFrom}{grammars.csv}{code:name} 
# And here is an example of the CodeFrom environment.
It does verbatim and holds 80 characters.

1........11........21........31........41........51........61........71........








1........11........21........31........41........51........61........71........
\end{CodeFrom}



\begin{CodeFrom}{ }{codelabel}

1........11........21........31........41........51........61........71........
\end{CodeFrom}

\noindent Here is an example of the Code environment (this one makes no reference to a file). And what about text below \refex{codelabel}, did that really work?


%----------------------------------------------------------------------------%
% CV syllable theory
%----------------------------------------------------------------------------%

\chapter{Basic functionality: CV syllable theory}\label{sec:cvsyllables}

In this chapter we work through an implementation of the CV syllable theory from  \cite[ch4]{prince::optimality::1993}. We begin by illustrating this familiar problem using simple constraints and work all the way through to typology generation. At the end of the chapter we give a brief tutorial on constraint writing (and debugging) along with exercises. 

\section{Inventories}

\paragraph{Inventory \& Features} For this first example we will use an inventory of only four symbols \{C, V, \D, \#\}. The symbols C and V are place-holders for consonants and vowels. `\D' is a separator for syllables and `\#' is a word-boundary marker.\footnote{%
%%%%%%%%%%%%%%%%%%%
We could have enclosed syllables in pairs of brackets (cf. our notation for feet in \S \ref{sec:stress}), but this notation is familiar and convenient for the current purposes. Also, for the model in this chapter we will assume that all forms (both underlying and surface) begin and end with `\#' symbols. This is a notational convention that facilitates keeping track of constraint violations and it does not impose any restrictions or represent any theoretical assumptions.} 
%%%%%%%%%%%%%%%%%%%
Symbols must be specified with unique features (two segments with identical features will not be distinguished from each other by pyPhon). After specifying the features that are associated with the segments to be used, the inventory itself must be declared. This makes it convenient to reuse the same feature specification files while restricting analyses to specific sets of symbols. 


\begin{CodeFrom}{syllables.csv}{ex:features}
# Define new symbols as referring to feature bundles
NewFeatures, C, +seg, +cons
NewFeatures, V, +seg, -cons
NewFeatures, ., -seg, +bnd, -wrd
NewFeatures, #, -seg, +bnd, +wrd

# The inventory of symbols. The inventory can use symbols defined by 
# NewFeatures statements like those above or it can use symbols from
# the default symbol set. (The latter is not yet fully implemented.) 
Inventory, C, V, ., #
\end{CodeFrom}


\noindent The material in \refex{ex:features} above comes from the file \textbf{syllables.csv}. In these files, the character `\#' at the beginning of a line marks the line as a comment.   

\section{Constraints} 
pyPhon provides a basic constraint-description-language (CDL) for defining constraints with regular expressions. Constraint descriptions are built from (up to) three parts: a \emph{left context}, a \emph{target}, and a \emph{right context} which are separated by `\_' underscores. Constraints assign one violation to each instance of the target occurring between the left and right contexts.  

The left and right contexts are optional and may use the OR operator `|' for disjunction and the Kleene-star operator `*' for iteration. The target is obligatory and it must be finite and nonempty (i.e., a set of strings of symbols can be targeted using disjunction but Kleene-star cannot occur in the description of the target). The scope of the operators is delimited with parentheses. Using symbols other than letters in the inventory (such as \# and \D) may confuse the constraint-parser. These should be `escaped' with the backslash. Consider the constraints \Con{Onset} and \Con{NoCoda} below.   

\begin{CodeFrom}{syllables.csv}{ex:namez}
# Define new finite-state constraints using regular expression syntax.
NewConstraint, onset, (\#|\.)_V_
NewConstraint, noCoda, _C_(\.|\#)
\end{CodeFrom}

\noindent \Con{Onset} has a left-context that specifies either a word- or syllable-boundary, a target of V, and no right-context; it assigns one violation to each V that occurs immediately after the word or syllable boundary. \Con{NoCoda} has no left-context, a target of C, and a right context that specifies a syllable or word boundary; it assigns one violation to each C that occurs immediately before a syllable or word boundary. 

For faithfulness constraints we introduce one more piece of notation; the colon is used to indicate the input-to-output mapping that is penalized by the constraint. We use parentheses below to visually separate individual i/o mappings but these are not necessary. When the colon is omitted, a constraint is assumed to be a markedness constraint (and thus assigns violations irrespective of the surface segments' input correspondence). 

\begin{CodeFrom}{syllables.csv}{ex:nameq} 
# Define new finite-state constraints using regular expression syntax.
NewConstraint, max, _(C:-)|(V:-)_
NewConstraint, depC, _-:C_
NewConstraint, depV, _-:V_
\end{CodeFrom}

\section{Filters} 
Filters are `hard' constraints. These are helpful when one wants to restrict the scope of analysis to particular structures or i/o-mappings. (The same effects can be obtained through the use of actual constraints and ranking restrictions.) The use of filters is a bit dangerous because, unlike constraints, they cannot be violated and thus it is easy to \emph{over-constrain} a problem so that some input forms have no output. As with constraints, if inputs are not specified the filter is assumed to be a surface filter. 

\begin{CodeFrom}{syllables.csv}{ex:namew}
# Define new finite-state filters using regular expression syntax. 
# Surface structure filter for the P&S_1993 five-constraint model:
NewSurfaceFilter, structureCVC, \# (((V|CV|VC|CVC)\.)* (V|CV|VC|CVC)\# | \#)
\end{CodeFrom}

\section{Model description files}

Example. Annotated. 

\section{Generating tableaux}

Input files. Tableaux files. Creating tableaux files by hand. See stress systems
for advanced topics (quadratic constraints, etc.). OT tableaux versus HG
tableaux. Pareto.

\section{Generating typologies and languages}

Typologies and grammatical restrictions. How to supply the restrictions: grammar
files. OT restrictions and HG restrictions. Marking winners/losers in the
tableaux file. Learning as specifying winners in tableaux (or as specifying an
ERC set restriction).

Coding TODO: allow selecting a specifc set of inputs for typology generation.
Proper command line arg parsing.

\section{More examples}

Extended syllable structure models. More constraint examples. Examples of what
happens when you add a bad constraint? Error reporting?

\section{Exercises}

\vbox{Some stuff here and then some more.

and then yet still more.



and more again.

Is this thing broken now?}

\newdimen\height
\setbox0=\vbox{Some stuff here and then some more.

and then yet still more.



and more again.

Is this thing broken now?}
\height=\ht0 \advance\height by \dp0
The height is: \the\height

%----------------------------------------------------------------------------%
% Stress systems
%----------------------------------------------------------------------------%

\chapter{Advanced functionality: Stress systems}\label{sec:stress}

Let's do tessmo and also gordon (perhaps also Kager). Now our symbol inventory
is bigger. R-volumes. Quadratica. T-orders.

\section{Gordon's model of QI stress}
\paragraph{Inventory} blah.

\paragraph{Constraints} Other ways of specifying constraints: dot files.
Quadratic constraints. 

\section{Riggle et al's model of QI stress}
No quadratics.

\section{Tesar and Smolensky's model of QS stress}

\section{Kager's model of QS stress}
No quadratics.

\section{Exercises}

%----------------------------------------------------------------------------%
% Other functions
%----------------------------------------------------------------------------%

\chapter{Other functions and the future}\label{chap:other}

\section{T-orders}

\section{r-volume}

\section{Learning simulations}

\section{Comparison with typological data}

\section{Exercises}


%----------------------------------------------------------------------------%
% Algorithms
%----------------------------------------------------------------------------%

\chapter{Algorithms}\label{chap:Algorithms}

How much do we get into here?

%----------------------------------------------------------------------------%
% Python Code Documentation
%----------------------------------------------------------------------------%

\chapter{Python Code Documentation}\label{chap:Code}

This should be generated automatically 


%----------------------------------------------------------------------------%
% References and such
%----------------------------------------------------------------------------%
% \backmatter

%%%%%%%%%-%%%%%%%%%-%%%%%%%%%-%%%%%%%%%-%%%%%%%%%-%%%%%%%%%-%%%%%%%%%-%%%%%%%%%%
%../\..../\..../\..../\..../\..../\..../\..../\..../\..../\..../\..../\..../\..%
%./  \../  \../  \../  \../  \../  \../  \../  \../  \../  \../  \../  \../  \.%
%/    \/    \/    \/    \/    \/    \/    \/    \/    \/    \/    \/    \/    \%
%
\bibliographystyle{citeling/PASCj}
%
\bibliography{citeling/citeLing}  																				 %
%\    /\    /\    /\    /\    /\    /\    /\    /\    /\    /\    /\    /\    /%
%.\  /..\  /..\  /..\  /..\  /..\  /..\  /..\  /..\  /..\  /..\  /..\  /..\  /.%
%..\/....\/....\/....\/....\/....\/....\/....\/....\/....\/....\/....\/....\/..%
%%%%%%%% %%%%%%%% %%%%%%%% %%%%%%%% %%%%%%%% %%%%%%%% %%%%%%%% %%%%%%%% %%%%%%%%

\end{document}

%%%%%%%%%-%%%%%%%%%-%%%%%%%%%-%%%%%%%%%-%%%%%%%%%-%%%%%%%%%-%%%%%%%%%-%%%%%%%%
%./\..../\..../\..../\..../\..../\..../\..../\..../\..../\..../\..../\..../\.%
%/  \../  \../  \../  \../  \../  \../  \../  \../  \../  \../  \../  \../  \%
%    \/    \/    \/    \/    \/    \/    \/    \/    \/    \/    \/    \/    %
%./\..../\..../\..../\..../\..../\..../\..../\..../\..../\..../\..../\..../\.%
%/  \../  \../  \../  \../  \../  \../  \../  \../  \../  \../  \../  \../  \%
%    \/    \/    \/    \/    \/    \/    \/    \/    \/    \/    \/    \/    %
%%%%%%%% %%%%%%%% %%%%%%%% %%%%%%%% %%%%%%%% %%%%%%%% %%%%%%%% %%%%%%%% %%%%%%



%----------------------------------------------------------------------------%
% A note on file IO in LaTeX from: http://stackoverflow.com/questions/2671079
%----------------------------------------------------------------------------%

TeX has support for file IO, and you can take advantage of this. To create a new input filehandle, you execute \newread\readFH; at this point, \readFH is a number representing a channel on which you can read or write (you've already seen one of these, the special channel 18). To open the file, you run \immediate\openin\readFH=filename.ext; now, reading from channel \readFH will read lines from filename.ext. To actually read from the file, you run \immediate\read\readFH to \nextline; this reads one line from \readFH and puts it in \nextline. Closing the file is then done with \immediate\closein\readFH.

Note that this treats newlines as spaces; if you have a file containing e.g.

foo
bar

and read a line into \nextline, it will be as though you wrote \def\nextline{foo }. To avoid this, you set \endlinechar to -1.

Overall, then, your example would look like this:

\newread\myinput
% We use '\jobname.temp' to create a uniquely-named temporary file
\immediate\write18{some command > '\jobname.temp'}
\immediate\openin\myinput=\jobname.temp
% The group localizes the change to \endlinechar
\bgroup
  \endlinechar=-1
  \immediate\read\myinput to \localline
  % Since everything in the group is local, we have to explicitly make the
  % assignment global
  \global\let\myresult\localline
\egroup
\immediate\closein\myinput
% Clean up after ourselves
\immediate\write18{rm -f -- '\jobname.temp'}
\dosomething{\myresult}

You could probably abstract this into a macro, but precisely what parts ought to be parametrized probably depends on your specific use case.

Also, just for future reference: creating filehandles to write to is done with \newwrite, you open them with \immediate\openout\writeFH=filename.ext, you write to them with \immediate\write\writeFH{some text}, and you close them with \immediate\closeout\writeFH.

